package businessServlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tecnick.htmlutils.htmlentities.HTMLEntities;

import controller.Controller;

import language.LangFactory;
import language.LangIntrf;

public class GetFindOrderForm extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		LangFactory langFactory= new LangFactory();
		String langName = req.getParameter("lang");
		LangIntrf lang =null;
		if(langName!=null){
			lang = langFactory.getLang(req.getParameter("lang"));
			session.setAttribute("lang",langName);
		}
		else
			lang = langFactory.getLang((String)session.getAttribute("lang"));
		PrintWriter  out = resp.getWriter();
		out.println("<div id=\"searchBox\">");
		out.println("<img src=\"/closed12.png\" id=\"closeBox\"/>");
		out.println("<form id=\"FindOrder\" action=\"showOneOrder.jsp\" method=\"get\" target=\"_blank\" accept-charset=\"ISO-8859-1\">");       
		out.println("<table dir=\""+lang.getDirection()+"\">");
		out.println("<tr><td align=\""+lang.getAlign()+"\">"+HTMLEntities.htmlentities(lang.getCOMPANY_NAME_LABEL()) +"</td></tr>");
		out.println("<tr><td align=\""+lang.getAlign()+"\"><select name=\"bizName\" >");
		Controller controller = Controller.getInstance();
		ArrayList<String> bizNameList = controller.allBizNameArray();
		ArrayList<String> bizUserList = controller.allBizUserNameArray();
		if(bizNameList==null || bizUserList==null){
		    System.out.println("error!!!!!!!!!!");
			System.out.println(bizNameList);
			System.out.println(bizUserList);
		}
		for(int i=0;i<bizNameList.size();i++){
			out.println("<option value=\""+bizUserList.get(i)+"\">"+bizNameList.get(i)+"</option>");
		}
		out.println("</select></td></tr>");
		out.println("<tr><td align=\""+lang.getAlign()+"\">"+HTMLEntities.htmlentities(lang.getORDER_NUBER_LABEL()) +"</td></tr>");
		out.println("<tr><td align=\""+lang.getAlign()+"\"><input type=\"text\" name=\"orderNum\" /></td></tr>");
		out.println("<tr><td align=\""+lang.getAlign()+"\">"+HTMLEntities.htmlentities(lang.getPHONE_NUMBER_LABEL()) +"</td></tr>");
		out.println("<tr><td align=\""+lang.getAlign()+"\"><input type=\"text\" name=\"phone\" /></td></tr>");
		if(lang.getAlign().equals("left")){ 
			out.println("<tr><td align=\"right\"><button type=\"submit\">"+HTMLEntities.htmlentities(lang.getFIND_BUTTON()) +"</button></td></tr>");
		}
		else{ 
			out.println("<tr><td align=\"left\"><button type=\"submit\">"+HTMLEntities.htmlentities(lang.getFIND_BUTTON()) +"</button></td></tr>");
		}
		out.println("</table>");
		out.println("<h5></h5>");
		out.println("</form>");
		resp.setStatus(200);
		out.flush();
		out.close();
	}
}
